using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Reflection;
using System.Text;
using System.Web;
using Castle.ActiveRecord;
using NHibernate.Expression;

namespace WOODIFramework.UI.Model
{
    [ActiveRecord("Category")]
    public class Category : ActiveRecordBase<Category>
    {
        #region Fields

        private int _id;
        private string _name;
        private string _description;

        #endregion

        #region Properties

        [PrimaryKey(PrimaryKeyType.Identity)]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        [Property]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        [Property]
        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        #endregion

        #region Constructor

        public Category()
        {
        }

        private Category(string Name)
        {
            this.Name = Name;
        }

        #endregion

        #region Public Methods

        #region Public Static Methods

        public static Category CreateCategory()
        {
            return new Category();
        }

        public static Category CreateCategory(string Name)
        {
            return new Category(Name);
        }

        public static Category FindCategoryByName(string Name)
        {
            ICriterion criteria = Expression.Eq("Name", Name);
            Category category = Category.FindFirst(criteria);
            return category;
        }

        public static Category FindCategoryById(int Id)
        {
            ICriterion criteria = Expression.Eq("Id", Id);
            Category category = Category.FindFirst(criteria);
            return category;
        }
        
        #endregion

        #endregion
    }
}
